package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.InAddPublicationOrderView;
import com.cloudsigns.factorymanager2.engineering.model.AddPublicationOrderModel;
import com.cloudsigns.factorymanager2.engineering.model.InAddPublicationOrderModel;

/**
 * Created by tony on 2018/5/5.
 */

public class AddPublicationOrderPresenter {
    private InAddPublicationOrderView view;
    private InAddPublicationOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public AddPublicationOrderPresenter(InAddPublicationOrderView view) {
        this.view = view;
        this.model = new AddPublicationOrderModel();
    }

    public void addPublicationOrder() {


        model.addPublicationOrder(view.getBeginDate(), view.getCompleteDate(), view.getIndustryCategory(), view.getMediaList(), view.getPicList(), view.getPublicationContent(), view.getRegionId(), view.getRegionName(), new AddPublicationOrderModel.OnAddPublicationOrderListener() {
            @Override
            public void addPublicationOrderSuccessed(final String id) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.addPublicationOrderSuccessed(id);
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void addPublicationOrderFailed(final String desc) {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.showFailedError(desc);
                        view.hideLoading();
                    }
                });
            }
        });

    }
}
